#ifndef CUDA_PERSON_H
#define CUDA_PERSON_H
#include "CudaEpiModel.h"
#include <sys/time.h> 
#include <omp.h>

using namespace std;

struct CPUtoGPUPerson{
	unsigned char status;	
	char iday;    
	unsigned char ibits;
	unsigned char vbits;
	unsigned char vday;
	
	CPUtoGPUPerson(){}
	
	__host__
	void CopyFromCPU(Person& p){
		status = p.status;
		iday = p.iday;
		ibits = p.ibits;
		vbits = p.vbits;
		vday = p.vday;
	}
};

struct CPUtoGPUPersonOp{
	CPUtoGPUPerson* temp;
	
	CPUtoGPUPersonOp(CPUtoGPUPerson* _temp){temp = _temp;}
	
	__device__
	void operator()(Person& p){
		CPUtoGPUPerson& tp = temp[p.id];
		p.status = tp.status;
		p.iday = tp.iday;
		p.ibits = tp.ibits;
		p.vbits = tp.vbits;
		p.vday = tp.vday;
	}
};

typedef thrust::device_vector<CPUtoGPUPerson> dCPUtoGPUPersonVec;
typedef vector<CPUtoGPUPerson> hCPUtoGPUPersonVec;

struct GPUtoCPUPerson{
	unsigned char status;	
	char iday;    
	unsigned char ibits;
	int nInfectedTime;
	
	double pri;
	double prs;
	
	GPUtoCPUPerson(){}
	
	__host__
	void CopyToCPU(Person& p){
		p.status = status;
		p.iday = iday;
		p.ibits = ibits;
		p.nInfectedTime = nInfectedTime;
		p.pri = pri;
		p.prs = prs;
	}
};

struct GPUtoCPUPersonOp{
	GPUtoCPUPerson* temp;
	
	GPUtoCPUPersonOp(GPUtoCPUPerson* _temp){temp = _temp;}
	
	__device__ 
	void operator()(Person& p){
		GPUtoCPUPerson& tp = temp[p.id];
		tp.status = p.status;
		tp.iday = p.iday;
		tp.ibits = p.ibits;
		tp.nInfectedTime = p.nInfectedTime;
		tp.pri = p.pri;
		tp.prs = p.prs;
	}
};

typedef thrust::device_vector<GPUtoCPUPerson> dGPUtoCPUPersonVec;
typedef vector<GPUtoCPUPerson> hGPUtoCPUPersonVec;


void CopyFromCPUtoGPU(
	vector<Person>& cpu_person, dPersonVec* gpu_person,
	hCPUtoGPUPersonVec* cpu_temp_person, dCPUtoGPUPersonVec* gpu_temp_person,int size);
	

int comparePpl(Person& p1, Person& p2);


void CopyFromGPUtoCPU(
	vector<Person>&  cpu_person, dPersonVec* gpu_person,
	hGPUtoCPUPersonVec* cpu_temp_person, dGPUtoCPUPersonVec* gpu_temp_person,int size);






#endif
